package com.rran.study.chat.user.controller;

import com.rran.study.chat.common.base.BaseController;
import com.rran.study.chat.common.model.Response;
import com.rran.study.chat.user.dto.request.LoginWithPwdDTO;
import com.rran.study.chat.user.dto.request.LoginWithSmsDTO;
import com.rran.study.chat.user.dto.request.QueryUserInfoDTO;
import com.rran.study.chat.user.dto.request.UserInfoDTO;
import com.rran.study.chat.user.dto.response.LoginVO;
import com.rran.study.chat.user.dto.response.UserInfoVO;
import com.rran.study.chat.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yy
 * @Type UserController.java
 * @Desc
 * @date 2020/8/11 10:01
 */
@Api(value = "用户相关")
@RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    @ApiOperation(value = "短信登录接口")
    @PostMapping("/loginWithSms")
    public Response<LoginVO> loginWithSms(@Validated  @RequestBody LoginWithSmsDTO loginWithSmsDTO, BindingResult bindingResult){
        checkParameters(bindingResult);
        return userService.loginWithSms(loginWithSmsDTO);
    }


    @ApiOperation(value = "账号密码登录接口")
    @PostMapping("/loginWithPwd")
    public Response<LoginVO> loginWithPwd(@RequestBody LoginWithPwdDTO loginWithPwdDTO, BindingResult bindingResult){
        checkParameters(bindingResult);
        return userService.loginWithPwd(loginWithPwdDTO);
    }

    @ApiOperation(value = "获取用户信息")
    @PostMapping("/getUserInfo")
    public Response<UserInfoVO> getUserInfo(@RequestBody QueryUserInfoDTO queryUserInfoDTO) {
        return userService.getUserInfo(queryUserInfoDTO);
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping("/updateUserInfo")
    public Response updateUserInfo(@RequestBody UserInfoDTO userInfoDTO){
        return userService.updateUserInfo(userInfoDTO);
    }


}
